package org.niit.common

import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
import org.apache.spark.streaming.Seconds
import org.niit.util.SparkUtil

/**
 * Date:2025/5/29
 * Author：Ys
 * Description:
 */
trait TApp extends App{ // 修改这里

  var spark:SparkSession  = _  //添加

  def start(master:String="local[*]",appName:String="Application")(op : => Unit):  Unit = {

    val sparkConf = new SparkConf().setMaster(master).setAppName(appName)

    val sc = SparkUtil.CreateSpark(sparkConf,Seconds(5))

    spark = SparkUtil.takeSpark() //修改这里

    val ssc = SparkUtil.takeSSC()
    sc.setLogLevel("ERROR")

    try{
      op //实际运行代码
    }catch {
      case ex => ex.printStackTrace()
    }

  }

}
